package org.zoomdev.zoom.rpc.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.zoomdev.zoom.rpc.utils.MessageEncoder;

public class RpcServerMessageToBytesEncoder extends MessageToByteEncoder {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf sendBuffer) throws Exception {
        if (o instanceof Command) {
            Command command = (Command) o;
            sendBuffer.clear();
            byte[] bytes = command.resultBytes;
            int id = command.id;
            short func = command.resultFunc;
            MessageEncoder.encode(sendBuffer, id, func, bytes);
        }
    }
}
